<!--
描述：教学计划-年级管理-添加专业组件
开发人：hqj
开发日期：2018年8月7日
-->
<template lang="pug">
    kalix-dialog.user-add(
    bizKey="grade"
    ref="kalixBizDialog"
    v-bind:form-model.sync="formModel"
    v-bind:visible="centerDialogVisible"
    v-bind:submitCustom="submitCustom")
        div.el-form(
        slot="dialogFormSlot"
        style="{width:100%}")
            kalix-search-transfer.userAdd(v-if="formModel.id>0"
            ref="kalixTransfer"
            v-bind:targetURL="targetURL"
            v-bind:sourceURL="sourceURL"
            v-bind:targetID="formModel.id"
            v-bind:sourceType="sourceType" v-bind:searchType="searchType" v-bind:searchFields="searchFields" title="年级专业设置"
            )
</template>

<script>
    import FormModel from './model'
    import {gradeURL, majorInfoURL,orgURL, TeachingUnitOrgID} from '../../config.toml'

    export default {
        name: 'SetTemplatAddMajors',
        data() {
            return {
                formModel: Object.assign({}, FormModel),
                userIds: [],
                ids: [],
                centerDialogVisible: false,
                sourceURL: majorInfoURL,
                targetURL: gradeURL,
                targetID: -1,
                searchType: 'majorids',
                sourceType: 'treeId',
                searchFields: [
                    {label: '院（系）部',type: 'tree',treeDataURL:orgURL,prop: '',parentNodeId:TeachingUnitOrgID}
                ]
            }
        },
        created() {
        },
        mounted() {
        },
        methods: {
//     baseDialog 提交按钮调用的方法
            submitCustom(baseDialog) {
                this.userIds = this.$refs.kalixTransfer.userIds.join(',')
                this.ids[0] = this.formModel.id
                this.ids[1] = this.userIds
                this.axios.request({
                    method: 'POST',
                    url: `${this.targetURL}/${this.formModel.id.toString()}/majorids`,
                    data: this.ids,
                    params: {}
                }).then(response => {
                    if (response.data.success) {
                        this.$KalixMessage.success(response.data.msg)
                        baseDialog.visible = false
                        baseDialog.$refs.dialogForm.resetFields()
                        baseDialog.submitComplete()
                    } else {
                        this.$KalixMessage.error(response.data.msg)
                        baseDialog.submitComplete()
                    }
                })
                console.log('this.ids', this.ids)
            },
            close() {
                this.onCancelClick()
            },
            onCancelClick() {
                console.log('dialog cancel button clicked !')
                this.centerDialogVisible = false
                this.$refs.dialogForm.resetFields()
//        this.$emit('update:formModel', JSON.parse(this.tempFormModel))
                this._afterDialogClose()
            },
            _afterDialogClose() {
                this.$KalixEventBus.$emit(this.bizKey + '-' + 'KalixDialogClose')
            }
        }
    }
</script>

<style lang="stylus">
</style>
